﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Web.netmonitor
{
    public partial class NetMonitor : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            SetDivePage(ref GridView1, ref GV);
            if (!IsPostBack)
            {
                //Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Session["userid"]));
                //DataSet roles = PhoneBook.Manage.SysRole.getGroupRole(user["groupid"].ToString());
                //Commons.ControlUtil.BindDDL(ddl_roleid, roles, "rolename", "roleid");

                this.txtStartTime.MyDateValue = DateTime.Now.AddDays(-1).ToString();
                this.txtEndTime.MyDateValue = DateTime.Now.AddDays(2).ToString();
                QueryData();
            }
        }

        public override void QueryData()
        {
            string monitortype = this.ddlMonitorType.SelectedValue;
            DateTime starttime = Convert.ToDateTime(this.txtStartTime.MyDateValue);
            DateTime endtime = Convert.ToDateTime(this.txtEndTime.MyDateValue);
            DataSet ds = new DataSet();
            if (!monitortype.Equals("-1"))
            {
                ds = PhoneBook.ServerMoniter.ServerMoniter.GetList(monitortype, starttime, endtime);//PhoneBook.Manage.LoginLog.listloginlog(usertype, username, starttime, endtime);
            }
            else
            {
                ds = PhoneBook.ServerMoniter.ServerMoniter.GetList(starttime, endtime);//PhoneBook.Manage.LoginLog.listloginlog(usertype, username, starttime, endtime);
            }
            //绑定数据集
            GVDataBind(ref GridView1, ref GV, ds);
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            QueryData();
        }

        protected void ChangeRowBackColor(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                bool iswarn = (bool)((DataRowView)e.Row.DataItem).Row["iswarn"];

                if (iswarn)
                {
                    e.Row.BackColor = System.Drawing.Color.Pink;
                }
            }
        }

        protected string GetMonitorTypeName(string strMonitorType)
        {
            string strMonitorTypeName = string.Empty;

            switch (strMonitorType)
            {
                case "CPU":
                    strMonitorTypeName = "CPU监测";
                    break;
                case "Memory":
                    strMonitorTypeName = "内存监测";
                    break;
                case "Storage":
                    strMonitorTypeName = "硬盘监测";
                    break;
                case "NET":
                    strMonitorTypeName = "网络监测";
                    break;
                case "Process":
                    strMonitorTypeName = "关键进程监测";
                    break;
                default:
                    strMonitorTypeName = "未知";
                    break;
            }
            return strMonitorTypeName;
        }
    }
}